
R3F_FNCT_IsObject_Visible = {
	private ["_obj", "_dist", "_return", "_ecart"];
	_obj = _this select 0;
	_dist = _this select 1;
	_return = true;
	if (_dist >= 0) then {
		_arr = playableUnits;
		{	_ecart = _x distance _obj;
			if (_ecart < _dist) then {
				_return = false;
			};
		} foreach _arr;
	} else {
		_return = false;
	};
	_return;
};
R3F_FNCT_GetPos = {
	private ["_item","_pos"];
	_item = _this select 0;
	_pos = switch (typeName _item) do {
		case "ARRAY" : {_item;};
		case "STRING" : {getPos ([_item] call R3F_FNCT_WhoIs);};
		case "GROUP" : {getPos (leader _item);};
		case "OBJECT" : {getPos _item;};
		default {[];};
	};
	if (typeName _pos != "ARRAY") then {_pos = [];};
	_pos;
};
R3F_FNCT_GetSideClass = {
	private "_side";
	_side = getNumber (configFile >> "CfgVehicles" >> (_this select 0) >> "side");
	if (_side == 3) then {
		_side = civilian;
	} else {
		if (_side == 0) then {
			_side = east;
		} else {
			if (_side == 1) then {
				_side = west;
			} else {
				if (_side == 2) then {
					_side = resistance;
				};
			};
		};
	};
	_side;
};
R3F_FNCT_UnitPos = {
	private ["_unit","_neck","_unitpos"];
	_unit = _this select 0;
	if (isPlayer _unit) then {
		// down :   [97,109,111,118,112,112,110,101,109,115,116,112,115,114,97,115,119,114,102,108,100,110,111,110]
		// middle : [97,109,111,118,112,107,110,108,109,115,116,112,115,114,97,115,119,114,102,108,100,110,111,110]
		// up :     [97,105,100,108,112,101,114,99,109,115,116,112,115,114,97,115,119,114,102,108,100,110,111,110,95,97,105,109,105,110,103,48,49]
		if ((toArray (animationState _unit) select 5) == 112) then {
			_unitpos = "DOWN";
		} else {
			if ((toArray (animationState _unit) select 5) == 107) then {
				_unitpos = "MIDDLE";
			} else {
				_unitpos = "UP";
			};
		};
	} else {
		//down 0.3 - middle 1.0 - up 1.5.
		_neck = ((_unit selectionPosition "Neck") select 2);
		if (_neck < 0.5) then {
			_unitpos = "DOWN";
		} else {
			if (_neck > 1.2) then {
				_unitpos = "UP";
			} else {
				_unitpos = "MIDDLE";
			};
		};
	};
	_unitpos
};
R3F_FNCT_Red = {
	"<t color='#f0ff0000'>" + _this + "</t>"
};
R3F_FNCT_Blue = {
	"<t color='#f0006699'>" + _this + "</t>"
};

/*
if !(isServer && isDedicated) then {
};
*/

if (isServer) then {
	R3F_FNCT_SafePos = {
		private ["_center","_radius","_x","_y","_pos","_i","_angle","_posx","_posy","_position","_obj","_near"];
		_center = _this select 0;
		_radius = _this select 1;
		_x = _center select 0;
		_y = _center select 1;
		_pos = [];
		for "_i" from 0 to 199 do {
			_angle = floor (random 360);
			_posx = _x - ((random _radius) * sin _angle);
			_posy = _y - ((random _radius) * cos _angle);
			if !(surfaceIsWater [_posx,_posy]) then {
				_position = [_posx,_posy,0];
				_obj = _position nearestObject "Static";
				_near = false;
				if !(isNull _obj) then {
					if (_position distance _obj < (sizeOf (typeOf _obj))) then {_near = true;};
				};
				if !(_near) then {_pos = _position;};
			};
			if (count _pos != 0) exitWith {};
		};
		_pos
	};
	R3F_FNCT_BuildingPos = {
		private ["_pos","_radius","_array_pos","_array","_p","_inside_pos"];
		_pos = _this select 0;
		_radius = _this select 1;
		_array_pos = [];
		_array = nearestObjects [_pos,["house"],_radius];
		if (count _array > 0) then {
			{	_p = 0;
				while {_inside_pos = _x buildingPos _p; format ["%1",_inside_pos] != "[0,0,0]"} do {
					_array_pos set [count _array_pos,_inside_pos];
					_p = _p + 1;
				};
			} forEach _array;
		};
		_array_pos
	};
	R3F_FNCT_RelPos = {
		private ["_posref","_dirref","_decal"];
		_posref = _this select 0;
		if (typeName _posref != "ARRAY") exitWith {};
		_dirref = _this select 1;
		if (typeName _dirref != "SCALAR") exitWith {};
		_decal = _this select 2;
		if (typeName _decal != "ARRAY") exitWith {};
		[	(_posref select 0) + ((_decal select 0) * cos _dirref) + ((_decal select 1) * sin _dirref),
			(_posref select 1) - ((_decal select 0) * sin _dirref) + ((_decal select 1) * cos _dirref),
			(_decal select 2)
		];
	};
};
